package apresentacao.caminhoneiro;

import android.os.Bundle;
import com.example.caminhoneiro.R;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
 
public class Activity_Menu_Principal extends Activity implements ListView.OnItemClickListener{
 
    private String[] drawerListViewItems = {"Meu Perfil", "Meus Fretes", "Buscar Fretes" ,"Sair"};
    private DrawerLayout drawerLayout;
    private ListView drawerListView;
    private ActionBarDrawerToggle actionBarDrawerToggle;
	FragmentManager fragment = getFragmentManager();
	FragmentTransaction fragment_t = fragment.beginTransaction();
	Bundle bundle;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.inicio);
        bundle = getIntent().getBundleExtra("bundle");
        inicializar();
    }
    
    public void inicializar(){
    	getActionBar().setDisplayShowTitleEnabled(false);
    	getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.holo_blue_dark)));
    	getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
        drawerListView = (ListView) findViewById(R.id.inicio_Lv);
        
        drawerListView.setAdapter(new ArrayAdapter<String>(this, R.layout.item_drawer, drawerListViewItems));
        
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.menu_2, R.string.drawer_open, R.string.drawer_close);
        drawerLayout.setDrawerListener(actionBarDrawerToggle);
        getActionBar().setDisplayHomeAsUpEnabled(true); 
        drawerListView.setOnItemClickListener(this);
    }
 
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
         actionBarDrawerToggle.syncState();
    }
 
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        actionBarDrawerToggle.onConfigurationChanged(newConfig);
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		
		switch(arg2){
			case 0:{
//		        Fragment_Meu_Perfil fragment_meu_perfil = new Fragment_Meu_Perfil();
//		        fragment_meu_perfil.setArguments(bundle);
//				fragment_t = fragment.beginTransaction();
//		        fragment_t.replace(R.id.Ll_Fragment,fragment_meu_perfil);
//		        fragment_t.commit();
		        break;
			}
			case 1:{
//				AsyncTask_Meus_Enderecos task = new AsyncTask_Meus_Enderecos(bundle.getInt("idProdutor"), this,0);
//				task.execute();
//				Fragment_Meus_Fretes f1 = new Fragment_Meus_Fretes();
//				fragment_t = fragment.beginTransaction();
//				fragment_t.replace(R.id.Ll_Fragment, f1);
//				fragment_t.commit();
				break;
			}
			case 2:{
				Fragment_Buscar_Frete f1 = new Fragment_Buscar_Frete();
				fragment_t = fragment.beginTransaction();
				fragment_t.replace(R.id.Ll_Fragment, f1);
				fragment_t.commit();					
				break;
			}
			case 3:{
				break;
			}
			case 4:{
//				Fragment_Novo_Frete f1 = new Fragment_Novo_Frete();
//		        f1.setArguments(bundle);
//				fragment_t = fragment.beginTransaction();
//				fragment_t.replace(R.id.Ll_Fragment, f1);
//				fragment_t.commit();
				break;
			}
			case 5:{
				break;
			}
		}
		drawerLayout.closeDrawer(drawerListView);
	}
}